<template>
  <div class="out_container">
    <el-container>
      <el-header>
        <div>
          <img src="../assets/heima.png" alt="" />
          <span>电商管理后台</span>
        </div>
        <el-button type="info" @click="loginOut">退出</el-button>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse? '64px':'200px'">
          <div class="toggleSide" @click="toggleCollapse">|||</div>
          <el-menu
            unique-opened
            active-text-color="#409eff"
            text-color="#fff"
            background-color="#373d41"
            :default-active="activePath"
            class="el-menu-vertical-demo"
            :collapse-transition="false"
            :collapse="isCollapse"
            router
            >
            <!-- 一级导航 -->
            <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
              <template slot="title">
                <i :class="iconObj[item.id]"></i>
                <span>{{item.authName}}</span>
              </template>
              <!-- 二级导航 -->
              <el-menu-item :index="'/'+citem.path" v-for="citem in item.children" :key="citem.id" @click="subMenuactive('/'+citem.path)">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{citem.authName}}</span>
                </template></el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activePath:'',
      isCollapse: false,
      menuList: [],
      iconObj: {
        '125': 'iconfont icon-user',
        '103': 'iconfont icon-tijikongjian',
        '102': 'iconfont icon-danju',
        '101': 'iconfont icon-shangpin',
        '145': 'iconfont icon-baobiao',
      }
    }
  },
  created() {
    this.getMenuList()
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    loginOut() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    async getMenuList() {
      const { data: ret } = await this.$http.get('menus')
      // console.log(ret)
      if(ret.meta.status !== 200) this.$mesage.error(ret.meta.msg)
      this.menuList = ret.data
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
    },
    subMenuactive(act) {
      window.sessionStorage.setItem('subMenuactive', act)
      this.activePath = act
    }
  }
}
</script>

<style lang="less" scoped>
.el-container,
.out_container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  > div {
    display: flex;
    align-items: center;
    span {
      font-size: 18px;
      color: #fff;
      padding-left: 15px;
    }
  }
}
.el-aside {
  width: 20%;
  background-color: #373d41;
  .el-menu{
    border-right: none;
  }
}
.iconfont {
  padding-right: 5px;
}
.toggleSide{
  background-color: #40564a;
  line-height: 24px;
  color: #fff;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
